<?php
/**
 * Inclusion de l'en-tête
 */
 session_start();
include 'views/head.php';
echo '<body>';

include 'views/header.php';

if(isset($_GET['section'])){

	$controller_file = dirname(__FILE__).'/controllers/controller_' . $_GET['section'] . '.php';
	
	if(is_file($controller_file)) {

		include $controller_file;

		$controller = 'controller_' . $_GET['section'];

		if(class_exists($controller)) {

			$c = new $controller;
				if(isset($_GET['action'])) {
				$maction = $_GET['action'];
				
				if(method_exists($c, $maction)) {

					call_user_func(array($c,$maction));
				}
			} else {
				header('Location: '.$_SERVER['PHP_SELF']);
			}
		}
	}
} else {
	header('Location: ?section=accueil&action=show');
	exit();
}
if(isset($_SESSION['message'])) {
	echo '<h1>' . $_SESSION['message'] . '</h1>';
	unset($_SESSION['message']);
}

echo '</div></body>';
?>
